﻿using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Wasion.HHU.Data.Models;
using Wasion.HHU.Data.Repositories;
using SQLite.Net;
using System;
using System.Linq.Expressions;

namespace Wasion.HHU.Data.Repositories
{
    public class VSchItemObAttrMthDbRepository : BaseDbRepository
    {
        public VSchItemObAttrMthDbRepository() : base()
        {

        }
        public VSchItemObAttrMthDbRepository(SQLiteConnection connection)
            : base(connection)
        {
        }

        public Task<List<VSchItemObAttrMth>> GetAllList()
        {
            List<VSchItemObAttrMth> VSchItemObAttrMths;

            lock (databaseLock)
            {
                VSchItemObAttrMths = DbConnection.Table<VSchItemObAttrMth>().
                    ToList();
            }
            return Task.FromResult(VSchItemObAttrMths);
        }

        public Task<List<VSchItemObAttrMth>> GetList(Expression<Func<VSchItemObAttrMth, bool>> filter)
        {
            List<VSchItemObAttrMth> VSchItemObAttrMths;

            lock (databaseLock)
            {
                VSchItemObAttrMths = DbConnection.Table<VSchItemObAttrMth>().
                    Where(filter).
                    ToList();
            }
            return Task.FromResult(VSchItemObAttrMths);
        }

        public void Insert(VSchItemObAttrMth vSchItemObAttrMth)
        {
            lock (databaseLock)
            {
                DbConnection.CreateTable<VSchItemObAttrMth>();
                DbConnection.Insert(vSchItemObAttrMth);
            }
        }

        public void Update(VSchItemObAttrMth vSchItemObAttrMth)
        {
            lock (databaseLock)
            {
                DbConnection.Update(vSchItemObAttrMth);
            }
        }

        public VSchItemObAttrMth Find(object primaryKey)
        {
            VSchItemObAttrMth vSchItemObAttrMth;

            lock (databaseLock)
            {
                vSchItemObAttrMth = DbConnection.Find<VSchItemObAttrMth>(primaryKey);
            }
            return vSchItemObAttrMth;
        }

        public void Delete(object primaryKey)
        {
            lock (databaseLock)
            {
                DbConnection.Delete<VSchItemObAttrMth>(primaryKey);
            }
        }
    }
}
